﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

namespace Ewts.Production
{
    public partial class BarcodeSmallImg : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                int barCodeID = 0;
                if (Request["barCodeID"] != null && Request["barCodeID"].ToString().Trim() != "")
                {
                    barCodeID = int.Parse(Request["barCodeID"].ToString());
                }
                DataLib.BLL.BarCode bBll = new DataLib.BLL.BarCode();
                DataLib.Model.BarCode bModel = bBll.GetModel(barCodeID);

                if (bModel != null)
                {
                    DataLib.Model.Vload vmodel = null;
                    DataLib.BLL.Vload vbll = new DataLib.BLL.Vload();
                    if (bModel.ParmentID != null && bModel.ParmentID != 0)
                    {
                        vmodel = vbll.GetModelByOutID((int)bModel.ParmentID);
                    }
                    DataLib.Model.BarCode barCodeM = bBll.GetByValue(bModel.barcodevalue);


                    if (barCodeM != null )
                    {
                        lblLoad.InnerText = bModel.loadnumv;
                        lblDate.InnerText = ((DateTime)bModel.createdate).ToShortDateString();
                       // lblStorage.InnerText = storPosM.storagecode;
                        lblGoodsName.InnerText = barCodeM.goodsname;
                       // lblGwt.InnerText = barCodeM.gwt.ToString();

                        lblqty.InnerText = barCodeM.qty.ToString();
                        lblnwt.InnerText = barCodeM.nwt.ToString();
                        lblCode1.InnerText = GetTrimBarcode(barCodeM.barcodevalue.ToUpper());
                        lblnwt_b.InnerText = barCodeM.nwt.ToString();
                       
                        lblqty2.InnerText = barCodeM.qty.ToString();
                        lblCode2.InnerText = GetTrimBarcode(barCodeM.barcodevalue.ToUpper());
                    }

                    img1.ImageUrl = "/ashx/BarCodePrint.ashx?code=" + barCodeM.barcodevalue.ToUpper() + "&height=30";
                    img2.ImageUrl = "/ashx/BarCodePrint.ashx?code=" + barCodeM.barcodevalue.ToUpper() + "&height=30";
                }
            }
        }

        /// <summary>
        /// 设置空格的Barcode
        /// </summary>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public string GetTrimBarcode(string barcode)
        {
            string str = barcode;

            if (str.Length == 30)
            {
                str = str.Insert(27, " ");
                str = str.Insert(17, " ");
                str = str.Insert(9, " ");
            }
            else if (str.Length == 26)
            {
                str = str.Insert(23, " ");
                str = str.Insert(13, " ");
                str = str.Insert(5, " ");
            }

            return str;
        }

    }
}